﻿Imports System.Text
Namespace TransactionSales
    Public Class clsview_SalesInput
        Inherits ADODBU.Recordset

        Private mFieldList As New ArrayList
        Private mStrFieldList As String
        Private mStrSql As String
        Public Sub New()
            mFieldList.Add("view_SalesInput.BARCODE")
            mFieldList.Add("view_SalesInput.SIZE")
            mFieldList.Add("view_SalesInput.COLOR")
            mFieldList.Add("view_SalesInput.BARDESCR")
            mFieldList.Add("view_SalesInput.SLSQTY")
            mFieldList.Add("view_SalesInput.DISCACRAMOUNT")
            mFieldList.Add("view_SalesInput.SLSTOTAMT")
            mFieldList.Add("view_SalesInput.SLSPRICE")
            mFieldList.Add("view_SalesInput.SLSDISC")
            mStrSql = "Select BARCODE,SIZE,COLOR,BARDESCR,SLSQTY,DISCACRAMOUNT,SLSTOTAMT,SLSPRICE,SLSDISC from view_SalesInput  "
        End Sub

        Public Overloads Sub Open(cCriteria As String)
            Dim cSql As String
            cSql = mStrSql & cCriteria
            MyBase.IsCanUpdate = True
            Try
                MyBase.Open(cSql, "view_SalesInput", Me.DbConn)
            Catch e As Exception
                Me.ErrMessage = e.Message
            End Try
        End Sub


        Public Function GetRowList(dbConn As ADODBU.dbConn, cCriteria As String) As ADODBU.RowClassList(Of clsview_SalesInputRow)
            Dim cmd As System.Data.IDbCommand = dbConn.DBAFactory.GetCommand
            cmd.CommandText = Me.mStrSql & cCriteria
            cmd.CommandType = CommandType.Text
            cmd.Connection = dbConn.Connection
            Return GetDataFromReader(cmd.ExecuteReader)
        End Function

        Public Function GetRowList() As ADODBU.RowClassList(Of clsview_SalesInputRow)
            Return Me.GetDataFromReader(Me.DataTable.CreateDataReader)
        End Function
        Private Function GetDataFromReader(ByVal rdr As IDataReader) As ADODBU.RowClassList(Of clsview_SalesInputRow)
            Dim colData As New ADODBU.RowClassList(Of clsview_SalesInputRow)
            Dim xData As clsview_SalesInputRow
            Dim buffer() As Byte
            Dim len As Long
            Dim mStr As New System.IO.MemoryStream

            Do While rdr.Read
                xData = New clsview_SalesInputRow()
                If Not rdr.IsDBNull(0) Then
                    xData.BARCODE = rdr.GetString(0)
                End If
                If Not rdr.IsDBNull(1) Then
                    xData.SIZE = rdr.GetString(1)
                End If
                If Not rdr.IsDBNull(2) Then
                    xData.COLOR = rdr.GetString(2)
                End If
                If Not rdr.IsDBNull(3) Then
                    xData.BARDESCR = rdr.GetString(3)
                End If
                If Not rdr.IsDBNull(4) Then
                    xData.SLSQTY = rdr.GetInt32(4)
                End If
                If Not rdr.IsDBNull(5) Then
                    xData.DISCACRAMOUNT = rdr.GetDecimal(5)
                End If
                If Not rdr.IsDBNull(6) Then
                    xData.SLSTOTAMT = rdr.GetDecimal(6)
                End If
                If Not rdr.IsDBNull(7) Then
                    xData.SLSPRICE = rdr.GetDecimal(7)
                End If
                If Not rdr.IsDBNull(8) Then
                    xData.SLSDISC = rdr.GetString(8)
                End If
                colData.Add(xData)
            Loop
            rdr.Close()
            rdr.Dispose()
            Return colData
        End Function
        Public Function GetReader(ByVal dbConn As ADODBU.dbConn, ByVal cCriteria As String) As IDataReader
            Dim cmd As System.Data.IDbCommand = dbConn.DBAFactory.GetCommand
            cmd.CommandText = Me.mStrSql & cCriteria
            cmd.CommandType = CommandType.Text
            cmd.Connection = dbConn.Connection
            Return cmd.ExecuteReader
        End Function
        Public Function GetClassRow() As clsview_SalesInputRow
            Dim crData As New clsview_SalesInputRow
            crData = GetClassRow(Me.GetCurrentDataRow)
            Return crData
        End Function


        Public Function GetClassRow(recdata As ADODBU.Recordset) As clsview_SalesInputRow
            Dim crData As clsview_SalesInputRow
            crData = New clsview_SalesInputRow(recdata.GetCurrentDataRow)
            Return crData
        End Function


        Public Function GetClassRow(recdata As DataRow) As clsview_SalesInputRow
            Return New clsview_SalesInputRow(recdata)
        End Function


        Public Function SaveClassRow(crData As clsview_SalesInputRow, lAddnew As Boolean, Optional lTransaction As Boolean = False) As Boolean
            Dim lSavedata As Boolean
            If lAddnew Then
                MyBase.AddNew()
            End If
            crData.DataSource = Me
            crData.SaveToDataSource()
            lSavedata = True
            Try
                MyBase.Update(lTransaction)
                If MyBase.ErrMessage.Length <> 0 Then
                    lSavedata = False
                End If
            Catch e As Exception
                lSavedata = False
            End Try
            Return lSavedata
        End Function


    End Class
End Namespace